<template>
  <div class="login">
    <div class="login_box">
      <el-form
        ref="form"
        auto-complete="on"
        @submit.native.prevent
        :model="form"
        label-width="0"
        :rules="rules"
      >
        <div class="login_title">
          <h2>东营市公墓监管平台</h2>
          <h4 class="little_title">
           DongYing District Funeral vehicle monitoring platform
          </h4>
        </div>
        <div class="login_input">
          <el-form-item label="" prop="name">
            <el-input
              :key="passwordType"
              :type="passwordType"
              ref="password"
              placeholder="请输入账号"
              prefix-icon="el-icon-user"
              v-model="form.username"
              name="name"
              tabindex="1"
              auto-complete="on"
              @keyup.enter.native="login"
            >
              <i
                slot="suffix"
                @click="showPwd"
                class="iconfont"
                :class="
                  passwordType === 'password' ? 'icon-no_eye' : 'icon-eye'
                "
              ></i>
            </el-input>
          </el-form-item>
        </div>
        <div class="login_btn_box">
          <el-button
            :loading="loading"
            class="login_btn"
            type="primary"
            style="width: 100%; margin-bottom: 30px;"
            @click.native.prevent="login"
            >登录</el-button
          >
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {login} from '@/api/home.js'
export default {
  data() {
    return {
      loading: false,
      form: {
        username: "",
      },
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
      },
      passwordType: "password",
    };
  },
  methods: {
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    login() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          let res = await login({ ...this.form });
          this.loading = false;
          if (res.code !== 1) return this.$message.error(res.message);
          sessionStorage.setItem("screen_token", res.data.token);
          this.$router.push({path:"/home"});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100vw;
  height: 100vh;
  background: url("../assets/imgs/login_bg.png") no-repeat;
  background-size: cover;
  background-position-x: center;
  background-position-y: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  .login_box {
    width: 540px;
    height: 418px;
    background: url("../assets/imgs/login_box.png") no-repeat;
    background-size: contain;
    padding: 57px 72px 0 72px;
    text-align: center;
    .login_title {
      h2 {
        font-size: 33px;
        background: linear-gradient(#44dec5, #4ebcfa);
        background-clip: text;
        font-weight: 800;
        color: transparent;
        letter-spacing: 2px;
      }
      .little_title {
        color: #fff;
        font-size: 12px;
        font-weight: 100;
        letter-spacing: 1px;
      }
    }
    .login_input {
      margin: 62px auto;
      padding: 0 14px;
      /deep/ input::-webkit-input-placeholder {
        color: #fff;
      }
      /deep/ input::-moz-input-placeholder {
        color: #fff;
      }
      /deep/ input::-ms-input-placeholder {
        color: #fff;
      }
      /deep/ .el-input__inner {
        background: transparent;
        border: 1px solid #08ebfe;
        color: #fff;
      }
      /deep/ .el-input__prefix {
        color: #fff;
        .el-input__icon {
          font-weight: 600 !important;
        }
      }
    }
    .login_btn_box {
      padding: 0 12px;
      width: 100%;
      .login_btn {
        width: 100%;
        background-image: linear-gradient(to right, #08ebfe, #28bac1);
        color: #fff;
        // height: 50px;
        // line-height: 50px;
        font-size: 24px;
        border-radius: 6px;
        font-weight: 700;
        letter-spacing: 10px;
        cursor: pointer;
      }
    }
  }
}
</style>
